// Package api @Title api[简述该包的主要作用]
// @Description
// @Author cnHuaShao
// @since v0.0.1
// @Version v1.0.0
// @Date 2024/4/21 22:37
// @Update 2024/4/21 22:37
package api

import (
	"FinancialManagement/src/base/mess"
	"FinancialManagement/src/base/util"
	"FinancialManagement/src/business/common"
	"FinancialManagement/src/business/provincesCities"
	"github.com/gin-gonic/gin"
	"net/http"
)

// GetProvincesCities
// @Description: 获取省市区信息列表
// @param c
func GetProvincesCities(c *gin.Context) {
	provinces, err := provincesCities.GetProvincesCities()
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(910005010, err.Error()))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(provinces))
}

// GetAnnualProcurementOfVehicles
// @Description: 获取特定年份下不同采购车辆的实际采购总金额、总数量、总运费
func GetAnnualProcurementOfVehicles(c *gin.Context) {
	yearId := c.DefaultPostForm("yearId", "2024")
	data, err := common.GetAnnualProcurementOfVehicles(yearId)
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(910005010, err.Error()))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(data))
}

// GetActualSalesOfVehicles
// @Description: 获取特定年份下不同车辆的实际销售总金额、总利润
// @param c
func GetActualSalesOfVehicles(c *gin.Context) {
	yearId := c.DefaultPostForm("yearId", "2024")
	data, err := common.GetActualSalesOfVehicles(yearId)
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(910005010, err.Error()))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(data))
}

// GetPurchaseListOfYear
// @Description: 依据年份、客户ID获取不同客户总金额和斤数
// @param c
func GetPurchaseListOfYear(c *gin.Context) {
	yearId := util.ToInt(c.DefaultPostForm("yearId", "2024"))      // 当前年份
	customerID := util.ToInt(c.DefaultPostForm("customerId", "0")) // 客户ID
	data, err := common.GetPurchaseListOfYear(yearId, customerID)
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(910005010, err.Error()))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(data))
}

// GetSalesListOfYear
// @Description: 依据年份、客户ID获取不同销售总金额和斤数
// @param c
func GetSalesListOfYear(c *gin.Context) {
	yearId := util.ToInt(c.DefaultPostForm("yearId", "2024"))      // 当前年份
	customerId := util.ToInt(c.DefaultPostForm("customerId", "0")) // 客户ID
	data, err := common.GetSalesListOfYear(yearId, customerId)
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(910005010, err.Error()))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(data))
}
